package com.yz.android_baozou.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;


import com.yz.android_baozou.R;
import com.yz.android_baozou.adapter.My_FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * Created by Administrator on 2016/10/31.
 */

public class HomeFragment extends Fragment {
    @Bind(R.id.tablayout_fragment_Home)
    TabLayout tablayoutFragmentHome;
    @Bind(R.id.viewPager_home_main)
    ViewPager viewPagerMain;
    private Context mContext = null;
    //用来接收资源文件的标题数组
    private String[] mArr_home = null;
    //用来添加碎片集合
    private List<Fragment> mList_home = null;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
        mArr_home = getResources().getStringArray(R.array.array_home);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home_main, null);
        ButterKnife.bind(this, view);
        return view;
    }



    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initDatas();
        //创建适配器
        My_FragmentPagerAdapter adapter = new My_FragmentPagerAdapter(getActivity().getSupportFragmentManager(), mArr_home, mList_home);
        //绑定适配器
        viewPagerMain.setAdapter(adapter);
        //设置预加载左右各2页
        viewPagerMain.setOffscreenPageLimit(2);
        //将碎片集合和TabLayout绑定
        tablayoutFragmentHome.setupWithViewPager(viewPagerMain);
    }
    private void initDatas() {
        //创建home的碎片集合 并且依次添加viewpager的子碎片
        mList_home = new ArrayList<>();
        mList_home.add(new HomePage_Home_Fragment());
        mList_home.add(new UserSubmitions_Home_Fragment());
        mList_home.add(new Video_Home_Fragment());
    }


}














